<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <title>注册</title>
    <link href="{{asset('vendor/bootstrap/css/bootstrap.min.css')}}" rel="stylesheet">
    <link rel="stylesheet" href="{{asset('css/buz/style.css')}}" />
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="{{asset('js/buz/jquery.min.js')}}"></script>
    <script src="{{asset('js/buz/common.js')}}"></script>
    <script src="{{asset('vendor/bootstrap/js/bootstrapValidator.js')}}"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="{{asset('vendor/bootstrap/js/bootstrap.min.js')}}"></script>
</head>
<body class="bgwhite">
<div class="yhy-header">
    <div class="yhy-wrapper">
        <a href="javascript:;" class="header-logo">
            <img src="{{asset('image/logo.png')}}" />
        </a>
        <div class="header-txt">商户注册</div>
    </div>
</div>
<div class="yhy-loginBody">
    <div class="yhy-wrapper bgwhite mt20">
        <div class="register-box">
            <div class="register-steps register-steps-one">
                <ul>
                    <li class="fll steps-char steps-white">1.账号认证</li>
                    <li class="fll steps-char">2、密码设置</li>
                    <li class="fll steps-char">3、注册完成</li>
                </ul>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <!--<h3 class="panel-title">-->
                    账号注册
                    <!--</h3>-->
                    <span class="right"><em class="red">*</em>为必填项</span>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" id="register">
                        <div class="form-group">
                            <label for="firstname" class="col-xs-4 col-sm-2 control-label"><em class="red">*</em>注册邮箱：</label>
                            <div class="col-xs-10 col-sm-5 col-md-4 col-lg-4">
                                <input type="text" class="form-control" name="username" id="username">
                            </div>
                            <span class="remend">(电子邮箱是您登录商户后台的登录名)</span>
                        </div>
                        <div class="form-group">
                            <label for="lastname" class="col-xs-4 col-sm-2 control-label"><em class="red">*</em>手机号码：</label>
                            <div class="col-xs-10 col-sm-5 col-md-4 col-lg-4">
                                <input type="text" class="form-control" name="phone" id="phone">
                            </div>
                            <div class="col-xs-10 col-sm-5 col-md-6 col-lg-4">
                                <button type="button" class="btn btn-info" id="sendCode">发送验证码</button>
                            </div>
                            <div class="col-xs-10 col-sm-10 col-md-8 col-lg-8">
                                <span class="remend">(当您在账户信息变更、关键业务操作时都会进行身份确认，从而提高您的账户安全性)</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-xs-4 col-sm-2 control-label"><em class="red">*</em>验证码：</label>
                            <div class="col-xs-10 col-sm-5 col-md-4 col-lg-4">
                                <input type="text" class="form-control" name="sms_code">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="firstname" class="col-sm-2 control-label"></label>
                            <div class="col-xs-10 col-sm-5 col-md-4 col-lg-4">
                                <button type="button" class="btn btn-primary" id="forgetNext">下一步</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>


    </div>
</div>
{{--警告弹窗--}}
<div class="modal fade in"  tabindex="-1" role="dialog" id="errorModel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <h4 class="text-center"></h4>
            </div>
            <div class="modal-footer text-xs-center">
                <button type="button" class="btn btn-danger" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $('#register').bootstrapValidator({
        message: '这个值没有被验证',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            username: {
                message: '用户名不能为空',
                validators: {
                    notEmpty: {
                        message: '用户名不能为空'
                    },
                    regexp: {
                        regexp: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/,
                        message: '请输入正确的邮箱'
                    }
                }
            },
            phone: {
                message: '手机不能为空',
                validators: {
                    notEmpty: {
                        message: '手机不能为空'
                    },
                    stringLength: {
                        min: 11,
                        max: 11,
                        message: '手机号码为11位'
                    },
                    regexp: {
                        regexp: /^1[3|5|7|8]\d{9}$/gi,
                        message: '请输入正确的手机号码'
                    },
                }
            },
            sms_code: {
                message: '验证码不能为空',
                validators: {
                    notEmpty: {
                        message: '验证码不能为空'
                    },
                    stringLength: {
                        min: 6,
                        max: 6,
                        message: '验证码长度为6位'
                    },
                    regexp: {
                        regexp: /^[0-9]*$/,
                        message: '验证码全为数字'
                    },
                }
            }
        }
    }).on('success.form.bv', function (e) {
        // Prevent form submission
        e.preventDefault();
        // Get the form instance
        var $form = $(e.target);
        // Get the BootstrapValidator instance
        var bv = $form.data('bootstrapValidator');
        console.log($form)

        $.post("/api/auth/register", $form.serialize(), function (data) {
            console.log(data)
            if (data.code == 0){
                window.location.href = '/register_email?username=' + $('#username').val();
            }else if(data.code == 40003){
                var str = "";
                var obj = data.message;
                $.each(obj,function(i){
                    var childObj = obj[i];
                    for(var j=0;j<childObj.length;j++){
                        str += childObj[j]+"<br/>";
                    }
                });
                showMsg(str);
            }else{
                showMsg(data.message);
            }
        });
    });

    /*下一步*/
    $("#forgetNext").click(function(e){
        $('#register').bootstrapValidator('validate');
    });
    //发送验证码
    $("#sendCode").click(function(){
        var _that = $(this);
        var bootstrapValidator = $('#register').data("bootstrapValidator");
        bootstrapValidator.validateField('phone');

        console.log(bootstrapValidator.isValidField('phone'))
        if(bootstrapValidator.isValidField('phone')){
            console.log("提交");
//            setTime(_that);
            var phone_txt = $("#phone").val();
            sendcode(phone_txt,1, _that);
        }
    });



</script>


</html>
